//	ID : pallab81
// 	PROG : 10051_2
// 	LANG : C++
// 	2011-09-04-10.09.09 Sunday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}
int N;
int cases;
string cube[6]={ "front", "back", "left", "right", "top","bottom" };
int grid[550][6];
int dp[550][6];

inline void Read(){
    fo(i,0,N){
        fo(j,0,6){
            CI( grid[i][j] );
        }
    }
}
inline void ini(){
    foE(i,0,500){
        foE(j,0,100){
            dp[i][j]=1;
        }
    }
}

inline int Role(int id){
    if(id==0 || id==1 ){
        return id==0 ? 1 : 0;
    }
    if(id==2 || id==3 ){
        return id==2 ? 3 : 2;
    }
    if(id==4 || id==5 ){
        return id==4 ? 5 : 4;
    }
}

inline void back_track(int mx){
//        fo(i,0,N){
//            fo(j,0,6){
//                printf("%3d",dp[i][j]);
//            }
//            printf("\n");
//        }
//        printf("\n");
    stack< pair<int,string> > st;
    int r=N-1;
    int color=-1;
    while( r>=0 && mx){
        fo(i,0,6){
            if( dp[r][i]==mx && (color==-1 || color==grid[r][i]) ){
                //int id = color==-1 ? i : Role(i);
                int id = Role(i);
                //color = color==-1 ? grid[r][i] : grid[r][ Role(i) ];
                color = grid[r][ Role(i) ];
                st.push( mk(r, cube[ id ] ) );
                --mx;
                break;
            }
        }

        --r;
    }
    //cout<<r<<" "<<mx<<"\n";
    //cout<<"Size : "<<SZ(st)<<"\n";
    while( st.empty()==false ){
        pair< int, string > temp = st.top();
        st.pop();
        cout<<temp.f+1<<" "<<temp.s<<"\n";
    }
    cout<<"\n";
}

inline void Proc(){
    ini();
    int mx = 1;
    fo(i,1,N){
        fo(j,0,6){
            int color1 = grid[i][j];
            fo(x,0,i){
                fo(y,0,6){
                    int color2 = grid[x][y];
                    if( color1 == color2 ){
                        if( dp[i][ Role(j) ] < dp[x][y]+1 ){
                            dp[i][ Role(j) ] = dp[x][y]+1;
                            mx = max(mx,dp[i][Role(j)]);
                        }
                    }
                }
            }
        }

    }
    printf("Case #%d\n",cases);
    printf("%d\n",mx);
    back_track(mx);
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","rt",stdin);
    #endif

    cases=1;
    while( scanf("%d",&N)==1 && N!=0 ){
        Read();
        Proc();
        ++cases;
    }

return 0;
}
